﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace XRpgLibrary
{
    public class SortableBindingList<T> : BindingList<T>
    {
        public SortableBindingList(IList<T> list)
            : base(list)
        { }

        public SortableBindingList()
            : base()
        { }

        public void Sort(IComparer<T> comparer)
        {
            // Get list to sort
            List<T> items = this.Items as List<T>;

            // Apply and set the sort, if items to sort
            if (items != null)
                items.Sort(comparer);

            // Let bound controls know they should refresh their views
            this.OnListChanged(
              new ListChangedEventArgs(ListChangedType.Reset, -1));
        }
    }
}
